#include "bga/graphics/RenderBufferObject.h"

using namespace std;

namespace bga
{

RenderBufferObject::RenderBufferObject() : GLObject()
{
    /// generate object id
    this->id = generate();

    internalFormat = GL_DEPTH_COMPONENT;
    this->width = 0;
    this->height = 0;
}

RenderBufferObject::~RenderBufferObject()
{
    glDeleteRenderbuffersEXT(1, &(this->id));
}

void RenderBufferObject::bind() const
{
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, this->id);
}

void RenderBufferObject::unbind() const
{
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
}

void RenderBufferObject::allocateBuffer() const
{
    glRenderbufferStorage(GL_RENDERBUFFER_EXT, internalFormat, this->width, this->height);
}

void RenderBufferObject::setInternalFormat(GLenum internalFormat)
{
    this->internalFormat = internalFormat;
}

GLenum RenderBufferObject::getInternalFormat() const
{
    return this->internalFormat;
}

void RenderBufferObject::setWidth(GLsizei width)
{
    this->width = width;
}

GLsizei RenderBufferObject::getWidth() const
{
    return this->width;
}

void RenderBufferObject::setHeight(GLsizei height)
{
    this->height = height;
}

GLsizei RenderBufferObject::getHeight() const
{
    return this->height;
}

GLuint RenderBufferObject::generate() const
{
    GLuint id;
    glGenRenderbuffersEXT(1, &id);
    return id;
}


}


